<?php

class Admin {

    protected $dbo = NULL;

    public function __construct() {

        $this->dbo  = &DBO::getInstance();
    }

    public function getVisits($count = 25, $offset = 0) {

        $res = $this->dbo->getAll('SELECT * FROM sys.visits
            WHERE ip <> ?
            ORDER BY id DESC OFFSET ? LIMIT ?',
            array(
                DBString::create($_SERVER['REMOTE_ADDR']),
                DBInteger::create($offset),
                DBInteger::create($count)
            ),
            DB_FETCHMODE_ASSOC);

        throwOnError($res);

        return $res;
    }

    public function getTotalVisits() {

        return $this->dbo->getOne('SELECT COUNT(*) FROM sys.visits WHERE timestamp >= CURRENT_DATE - 2');
    }
}